// components/theme-more/theme-more.ts
interface DataType {
  id: number,
  name: string,
}
interface DataTypeArray {
  [index: number]: DataType;
}
const MoreType = {
  grade: 0,
  class: 1,
  subject: 2,
}
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    subjectData: {
      type: Object,
      value: [] as DataTypeArray,
    },
    gradeData: {
      type: Object,
      value: [] as DataTypeArray,
    },
    classData: {
      type: Object,
      value: [] as DataTypeArray,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    MoreType: MoreType,
    grade: "",
    class: "",
    subject: "",
    isShowGrade: false,
    isShowClass: false,
    isShowSubject: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleShow(e: any) {
      const { type } = e.currentTarget.dataset;
      if (type === MoreType.grade) {
        this.setData({
          isShowGrade: !this.data.isShowGrade
        })
      }
      if (type === MoreType.class) {
        this.setData({
          isShowClass: !this.data.isShowClass
        })
      }
      if (type === MoreType.subject) {
        this.setData({
          isShowSubject: !this.data.isShowSubject
        })
      }
    },
    handleData(e: any) {
      const { type } = e.currentTarget.dataset;
      const { value } = e.detail
      if (type === MoreType.grade) {
        this.setData({
          grade: this.properties.gradeData[value].name,
        })
      }
      if (type === MoreType.class) {
        this.setData({
          class: this.properties.classData[value].name,
        })
      }
      if (type === MoreType.subject) {
        this.setData({
          subject: this.properties.subjectData[value].name,
        })
      }
    },
    handleSubmit() {
      this.triggerEvent('submit', {
        grade: this.data.grade,
        class: this.data.class,
        subject: this.data.subject,
      });
    }
  }
})